package com.example.demo.order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.order.service.IOOrderFeeDetailService;
import com.example.demo.order.entity.OOrderFeeDetail;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单费用明细表; 前端控制器
 * </p>
 *
 * @author tao
 * @since 2024-11-26
 */
@RestController
@RequestMapping("/oOrderFeeDetail")
    public class OOrderFeeDetailController {

    @Autowired
    private IOOrderFeeDetailService oOrderFeeDetailService;

    /**
    * 获取相关列表
     * @param current
     * @param size
     * @return
    */
    @GetMapping("/getOOrderFeeDetailList")
    public Result<?> getOOrderFeeDetailList(@RequestParam(value = "current", required = false, defaultValue = "1")Integer current,
                                            @RequestParam(value = "size", required = false, defaultValue = "10")Integer size,
                                            OOrderFeeDetail oOrderFeeDetail){

        Page<OOrderFeeDetail> page = new Page<>(current,size);
        QueryWrapper<OOrderFeeDetail> queryWrapper=new QueryWrapper<>(oOrderFeeDetail);
        queryWrapper.orderByDesc("id");
        return Result.ok(oOrderFeeDetailService.page(page,queryWrapper));
    }

    /**
         * 根据ID查询信息
         */
    @GetMapping("/getOOrderFeeDetailById")
    public Result<?> getOOrderFeeDetailById(Integer id){
        return Result.ok(oOrderFeeDetailService.getById(id));
    }

    /**
         * 修改
         */
    @PutMapping("/updateOOrderFeeDetail")
    @Transactional
    public Result<?> updateOOrderFeeDetail(@RequestBody OOrderFeeDetail oOrderFeeDetail){
        return Result.ok(oOrderFeeDetailService.updateById(oOrderFeeDetail));
    }

    /**
         * 新增
         */
    @PostMapping("/addOOrderFeeDetail")
    public Result<?> addOOrderFeeDetail(@RequestBody OOrderFeeDetail oOrderFeeDetail){
        return Result.ok(oOrderFeeDetailService.save(oOrderFeeDetail));
    }

    /**
         * 删除
         */
    @DeleteMapping("/deleteOOrderFeeDetailById")
    @Transactional
    public Result<?> deleteOOrderFeeDetail(Integer id){
        return Result.ok(oOrderFeeDetailService.removeById(id));
    }

    /**
     * 获取订单明细
     */
    @GetMapping("/getOrderFeeDetail")
    public Result<?> getOOrderFeeDetailList(String orderNo){
        return oOrderFeeDetailService.getOOrderFeeDetailList(orderNo);
    }
}

